﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LightControls
{
    public enum MessageType
    {
        INFORMATION, ERROR
    }

    public partial class MessagePanel : UserControl
    {
        public MessagePanel(string message, MessageType messageType)
        {
            InitializeComponent();
            if (messageType == MessageType.INFORMATION)
                setInfoTheme();
            else if (messageType == MessageType.ERROR)
                setErrorTheme();
            lblMessage.Text = message;
           
        }



        public event EventHandler OnCompleted;

        public void Show()
        {
            showStory.Begin();
        }
        
        private void setInfoTheme()
        {
            brdMain.Background = this.Resources["infoBgBrush"] as SolidColorBrush;
            brdMain.BorderBrush = this.Resources["infoBorderBrush"] as SolidColorBrush;
        }

        private void setErrorTheme()
        {
            brdMain.Background = this.Resources["errorBgBrush"] as SolidColorBrush;
            brdMain.BorderBrush = this.Resources["errorBorderBrush"] as SolidColorBrush;
        }

        public static void ShowInfo(string message, MessageType messageType, UIElement container)
        {
            MessagePanel mp = new MessagePanel(message, messageType);
        }

        public void ShowError(string message)
        {
            lblMessage.Text = message;
            showStory.Begin();
        }
        private void showStory_Completed(object sender, EventArgs e)
        {
            hideStory.Begin();
        }

        private void hideStory_Completed(object sender, EventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
            
            if (OnCompleted != null)
                OnCompleted(this, e);
        }
    }
}
